package com.atguigu.util

import org.apache.spark.SparkConf
import org.apache.spark.streaming.{Seconds, StreamingContext}

/**
 * description ：sparkStreaming base app
 * author      ：剧情再美终是戏 
 * mail        : 13286520398@163.com
 * date        ：Created in 2020/3/11 15:35
 * modified By ：
 * version:    : 1.0
 */
trait BaseApp {

  private var _appName = "default"

  private var conf: SparkConf = null

  def initAppName(appName: String): Unit = {
    if (null != appName && appName.length > 0) {
      _appName = appName
    }
  }

  def setConf(conf: SparkConf): Unit = {
    if (null == conf) {
      this.conf = new SparkConf().setMaster("local[1]").setAppName(_appName)
    } else {
      this.conf = conf
    }
  }

  def main(args: Array[String]): Unit = {
    // 创建 streamingContext
    val ssc = new StreamingContext(conf, Seconds(3))

    // 执行操作
    doSomething(ssc)

    // ssc 启动并一直运行
    ssc.start()
    ssc.awaitTermination()
  }

  def doSomething(ssc: StreamingContext)
}
